#include "widget.h"
#include "ui_widget.h"
#include "progressbar.h"
#include <QThread>
#include <QTimer>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    bar = new ProgressBar();

    bar->setMaxValue(100);
    bar->show();

    // 使用 QTimer 模拟进度更新
//    QTimer *timer = new QTimer(this);
//    int currentProgress = 0;

//    connect(timer, &QTimer::timeout, [=, &currentProgress]() mutable {
//        if (currentProgress <= 100) {
//            bar->setProgessBarCurValue(currentProgress);
//            currentProgress++;
//        } else {
//            timer->stop();
//            bar->close();
//        }
//    });

//    timer->start(100);  // 每 100ms 更新一次
    for (int i = 0; i <= 100; ++i) {
        bar->setProgessBarCurValue(i);
        //QCoreApplication::processEvents(); // 允许界面更新
        //QGuiApplication::processEvents();
        QApplication::processEvents();
        QThread::msleep(100); // 模拟耗时操作
    }
}

Widget::~Widget()
{
    delete ui;
}
